package com.Questions.hash;

import java.util.*;

/**
 * 两句话中的不常见单词
 */
public class leetcode884 {
    public String[] uncommonFromSentences(String s1, String s2) {
        Map<String, Integer> freq = new HashMap<String, Integer>();
        insert(s1, freq);
        insert(s2, freq);

        List<String> ans = new ArrayList<String>();
        for (Map.Entry<String, Integer> entry : freq.entrySet()) {
            if (entry.getValue() == 1) {
                ans.add(entry.getKey());
            }
        }
        return ans.toArray(new String[0]);
    }
    public void insert(String s,Map<String,Integer> freq){
        String[] arr=s.split(" ");//排除空格的方法
        for(String word:arr){
            freq.put(word,freq.getOrDefault(word,0)+1);
        }
    }
}
